package com.example.demo.server;

import com.example.demo.dao.DaoVideo;
import com.example.demo.pojo.Video;
import com.example.demo.util.DateUtil;
import com.example.demo.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
public class VideoSever {
    @Autowired
    DaoVideo daoVideo;
    public int saveVideoPath(MultipartFile file,String name,String videoClass){
        int code=200;
        try{
            String s= FileUtil.getFilePath(file,"E:/代码/ASP.net Web程序设计/web程序设大作业/后端/workspace/classVideo","http://localhost:8443/api/classVideo/",".flv");
            Video video=new Video();
            video.setVideoClass(videoClass);
            video.setVideoName(name);
            video.setVideoUrl(s);
            video.setVideoTime(DateUtil.getTimeStamp());
            video.setVideoId(FileUtil.getRandomString(8));
            daoVideo.save(video);
        }
        catch (Exception e){
            code=400;
        }
        return code;
    }
    public List<Video> getAllByClassId(String classId){
        return daoVideo.findAllByVideoClass(Sort.by("videoTime"),classId);
    }

}
